import com.google.api.translate.*
import com.google.jplurk.*

words1 = ['翻譯', 'translate']
words2 = ['英翻中', '中譯']
words3 = ['中翻英', '英譯']

words1.each {
	word ->
	
	if (plurk.content.startsWith(word)) {
		println "match ${word}"
		
		text = plurk.content.substring(word.length()).trim()
		
		utf8_length = text.length()
		byte_length = text.getBytes().length
		
		if (utf8_length.equals(byte_length)) {
			Translate.setHttpReferrer('http://www.plurk.com/');
			translatedText = Translate.execute(text, Language.ENGLISH, Language.CHINESE);
			matched++
			ship.response plurk.plurk_id, "${text}就是${translatedText}", Qualifier.FEELS
		}
		else {
			Translate.setHttpReferrer('http://www.plurk.com/');
			translatedText = Translate.execute(text, Language.CHINESE, Language.ENGLISH);
			matched++
			ship.response plurk.plurk_id, "${text} means ${translatedText}", Qualifier.FEELS
		}
	}
}

words2.each {
	word ->
	
	if (plurk.content.startsWith(word)) {
		println "match ${word}"
		text = plurk.content.substring(word.length())
		Translate.setHttpReferrer('http://www.plurk.com/');
		translatedText = Translate.execute(text, Language.ENGLISH, Language.CHINESE);
		matched++
		ship.response plurk.plurk_id, "${text}就是${translatedText}", Qualifier.FEELS
	}
}

words3.each {
	word ->
	
	if (plurk.content.startsWith(word)) {
		println "match ${word}"
		text = plurk.content.substring(word.length())
		Translate.setHttpReferrer('http://www.plurk.com/');
		translatedText = Translate.execute(text, Language.CHINESE, Language.ENGLISH);
		matched++
		ship.response plurk.plurk_id, "${text}就是${translatedText}", Qualifier.FEELS
	}
}

